package com.ydw.event_;

import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * 事件监听器
 *
 * @author HYL
 * @create 2017-07-06 下午4:11
 **/
@Component
public class EventListerner implements ApplicationListener<MyEvent> {
    /**
     * 这个方法是可以获得事件的所有属性的
     * @param myEvent
     */
    @Async//开启异步的处理
    @Override
    public void onApplicationEvent(MyEvent myEvent) {
        String msg = myEvent.getMsg();
        try {
            Thread.sleep(30000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("我监听到了这个事件,获得的命令是"+msg);
        System.out.println("我开始执行这个命令下面的任务了");
    }
}
